export const block: ICustomBlockOption = {
    name: "SToyWaterDrops",
    comments: "实现ShaderToy水波纹荡漾效果",
    document: "https://www.shadertoy.com/view/XdXGR7",
    target: "Fragment",
    inParameters: [
        {
            name: "inUV",
            type: "Vector2"
        },
        {
            name: "inTime",
            type: "Float"
        },
        {
            name: "inMouse",
            type: "Vector2"
        },
        {
            name: "source",
            type: "Object"
        }
    ],
    outParameters: [
        {
            name: "output",
            type: "Vector4"
        }
    ],
    "includes": [
        "//<helperFunctions> has a 'PI' declaration",
        "helperFunctions",
        "shaderToyDeclaration"
    ],
    entryFunctionName: "SToyWaterDrops",
    code: `
        const vec3 eps = vec3(0.01, 0.0, 0.0);

        float genWave1(float len)
        {
            float wave = sin(8.0 * PI * len + (-iTime*5.0));
            wave = (wave + 1.0) * 0.5;
            wave -= 0.3;
            wave *= wave * wave;
            return wave;
        }

        float genWave2(float len)
        {
            float wave = sin(7.0 * PI * len + (-iTime*5.0));
            float wavePow = 1.0 - pow(abs(wave*1.1), 0.8);
            wave = wavePow * wave;
            return wave;
        }

        float scene(float len)
        {
            return genWave1(len);
        }

        vec2 normal(float len)
        {
            float tg = (scene(len + eps.x) - scene(len)) / eps.x;
            return normalize(vec2(-tg, 1.0));
        }

        void SToyWaterDrops(vec2 inUV, float inTime, vec2 inMouse, sampler2D source, out vec4 fragColor)
        {
            iTime = inTime;
            iMouse.xy = inMouse;
            vec2 uv1 = inUV;


            vec2 so = iMouse.xy / iResolution.xy;
            vec2 pos2 = vec2(uv1 - so);
            vec2 pos2n = normalize(pos2);

            float len = length(pos2);
            float wave = scene(len);

            vec2 uv2 = -pos2n * wave/(1.0 + 5.0 * len);

            fragColor = texture(source, uv1 + uv2);
        }
    `
}